#! /usr/bin/python3
# -*- coding: UTF-8 -*-

if __name__ == "__main__":
	raise Exception("不支持从这里调用")

__version__ = "1.0"
__all__ = ["mousechsh_test"]

from com.mousechsh.common.data.json.MouseChshJson import mousechsh_json_to_json, mousechsh_json_from_json
from com.mousechsh.common.log.MouseChshLog import mousechsh_logging_data, mousechsh_logging
from com.mousechsh.common.middle.url.MouseChshUrl import MouseChshUrl
from com.mousechsh.common.util.MouseChshCodeUtil import mousechsh_crypto_encrypt, mousechsh_code_util_method_aes_128, \
	mousechsh_code_util_mode_ecb, mousechsh_code_util_padding_pkcs5, mousechsh_code_util_type_utf8string, \
	mousechsh_code_util_type_base64string, mousechsh_code_util_key_type_utf8string, \
	mousechsh_code_util_key_format_hex_list, mousechsh_crypto_sign, mousechsh_code_util_method_rsa_2048, \
	mousechsh_code_util_hash_sha2_256, mousechsh_code_util_padding_pkcs1, mousechsh_code_util_key_format_asn1_der_base64


def mousechsh_test(*, use_assert=False):
	return
	mousechsh_logging('开始运行【举例代码】相关代码：')
	keys = {
		'public':
			'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAqzhulPvhM0dyeLFStL1S'
			'rJhu5TcPVUvSFKJAL0FnRISesSrb+NzB76LnDgF0R92z3jcGCDBzZ0JhJu0NOMRl'
			'hOTSkllW4ZBI2nIbrc4WGzZr9uVbqNjAPQ87c2fIB4TCDaXMyVLzKh9KCJvHJ0J6'
			'JLea2qGBlsR8sEd/tKB/BcZ0a0O/Io+8Koi8tPqNOVqrsV/hcC/4rXBmG4dRfn4M'
			'nZ/rh9bhCChlEyzpDn4J4SJkWadkwBgpf2l+KgHGgkC1ci3m7xEn5uK/7SBIi71B'
			'WKWdasKo6cWzudJSs+Ywkqy6B9BNXxKoAAPB59EhN4ZjXPb24s6gdnyWpjk8gdf0'
			'RQIDAQAB',
		'private':
			'MIIEpQIBAAKCAQEAqzhulPvhM0dyeLFStL1SrJhu5TcPVUvSFKJAL0FnRISesSrb'
			'+NzB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nFN/GpsXGE'
			'C3Calp6w0HEI4+wXVh6aShCgKB3ifxQTzDQlknYOHMJa3CnKyEt/j4HZf6s7ymOF'
			'ATKjh5CQ4hwAn4iEC9mn0xLwnlnSq36iBq9UKuRjkxHDo4GTaJ8n6Cx1PpWf9OdK'
			'jM8EG0qjF3XIHZhoAXH/E7kCgYEAlrI5IUYbaJg/8cN5fBYgv3YvS1yGZxKNXFY3'
			'F17OZH4Xv5/zJ9RsY+CQDpKl0wNlgOcI+O03utwu9OFOHZAQCcWvr7OebCYeTAML'
			'r7dKU3ZEi36Uxl/1rcOdanM5v39dCH9XOipsKw/NI1VrbIBVscpkdvRCtacZxHT7'
			'wDHLJDkCgYEAgR7TgUq4HK+jnixYq2JR78C9YnZB+9t1tzEb7tTTXloivPesd2ER'
			'fXOEwDJwHas3q00UOzt5+kLUNmYpgZXA4qT14w+Kt1+VzjwNHwDkRV+WgBLxkSiZ'
			'l/YM6kXoB8VVkPI9BVSGKntwNOP2o3Vmv6n4MbS0jCDVZPRoIh2EW1I='
	}
	mousechsh_logging_data(keys, 'RSA密钥（2048位）为：')
	key = 'nWw8JkKvHD9F3XYk'
	mousechsh_logging_data(key, '数据加密处理的密钥为：')
	source_data = {
		'seqNo': '2022100916100598372',
		'pageItemIndex': 0,
		'pageSize': 50,
		'msg': '中文示例',
		'data': {
			'id': 'BAB3EA1C-5193-4FC3-B814-04D802846C08',
			'code': '596C7206-3605-4C5E-9B47-F74FA8CEE565',
			'user': '44DEAD51-886B-1708-4543-ED2559D0CAB7',
			'domain': '04BA7DCA-0FE9-448C-B97A-1ADFC255B90F',
			'app': '9FDA4E83-38C8-67A6-33AD-C7247018DA92',
			'loginTime': 1660030806,
			'alive': 3600,
			'expTime': 1660034406
		}
	}
	source_data_json = mousechsh_json_to_json(source_data)
	mousechsh_logging_data(source_data_json, '原始数据：')
	inner_data = source_data['data']
	inner_data_json = mousechsh_json_to_json(inner_data)
	mousechsh_logging_data(inner_data_json, '内部报文数据：')
	inner_data_encode = mousechsh_crypto_encrypt(
		inner_data_json,
		public_key=key,
		method=mousechsh_code_util_method_aes_128,
		mode=mousechsh_code_util_mode_ecb,
		padding=mousechsh_code_util_padding_pkcs5,
		source_type=mousechsh_code_util_type_utf8string,
		target_type=mousechsh_code_util_type_base64string,
		key_type=mousechsh_code_util_key_type_utf8string,
		key_format=mousechsh_code_util_key_format_hex_list
	)
	mousechsh_logging_data(inner_data_encode, '内部报文加密数据：')
	package_data = mousechsh_json_from_json(source_data_json)
	package_data['data'] = inner_data_encode
	package_data_json = mousechsh_json_to_json(package_data)
	mousechsh_logging_data(package_data_json, '处理完加密后的报文：')
	sign_data = MouseChshUrl()
	sign_data.set_search('seqNo', package_data['seqNo'])
	sign_data.set_search('pageItemIndex', package_data['pageItemIndex'])
	sign_data.set_search('pageSize', package_data['pageSize'])
	sign_data.set_search('msg', package_data['msg'])
	sign_data.set_search('data', package_data['data'])
	mousechsh_logging_data(sign_data.get_search(), '要签名的字符串：')
	sign_data_string = sign_data.get_search(sort=True, trim=True)
	mousechsh_logging_data(sign_data_string, '排序并处理后的要签名字符串：')
	sign_string = mousechsh_crypto_sign(
		sign_data_string,
		private_key=keys['private'],
		method=mousechsh_code_util_method_rsa_2048,
		hash_method=mousechsh_code_util_hash_sha2_256,
		mode=mousechsh_code_util_mode_ecb,
		padding=mousechsh_code_util_padding_pkcs1,
		source_type=mousechsh_code_util_type_utf8string,
		target_type=mousechsh_code_util_type_base64string,
		key_type=mousechsh_code_util_key_type_utf8string,
		key_format=mousechsh_code_util_key_format_asn1_der_base64
	)
	mousechsh_logging_data(sign_string, '签名结果：')
	package_data['sign'] = sign_string
	mousechsh_logging_data(mousechsh_json_to_json(package_data), '最终结果：')

	raise Exception('【示例代码】程序在此结束，停止运行')
